package com.example.backend.api.controller;


import com.example.backend.api.common.Result;
import com.example.backend.api.service.impl.DeptServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xwyzsn
 * @since 2023-03-07
 */
@RestController
@RequestMapping("/api/dept")
@CrossOrigin(origins = "*",maxAge = 3600)
public class DeptController {


    @Autowired
    private DeptServiceImpl deptService;

    @GetMapping("/getall")
    public Result getAll(){
        return deptService.getAll();
    }

    @PostMapping("update")
    public Result updateDept(@RequestParam(value = "dept_id") Integer id ,
                             @RequestParam(value = "dept_name") String name){
        return deptService.updateDept(id,name);
    }

    @PostMapping("add")
    public Result addDept(@RequestParam(value = "name") String name,
                          @RequestParam(value = "dept_id") Integer dept_id){
        return deptService.addDept(name,dept_id);
    }



}
